<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>程序设计——拼图文件生成 | 软工个人项目——拼图游戏</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="一、需求分析 使用像素图生成各种规格的拼图至文件 支持读取黑白、彩色的图像 使用BMP位图作为输入 题目文件数据组织结构合理，占用空间应尽量小，解析应尽量简单  二、题目文件设计对于文件的生成，我们需要从一张像素图来生成一个数组，即每行、每列的颜色点分布情况。显然根据规则，生成这个数组的方法是明确简单的。通过横向、纵向扫描数组的每一列、每一行，即可生成这个数组。最终生成的数组包含两部分，第一部分表">
<meta property="og:type" content="article">
<meta property="og:title" content="程序设计——拼图文件生成">
<meta property="og:url" content="http://bit-wxz.gitee.io/hexo/2021/01/25/%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1%E2%80%94%E2%80%94%E6%8B%BC%E5%9B%BE%E6%96%87%E4%BB%B6%E7%94%9F%E6%88%90/index.html">
<meta property="og:site_name" content="软工个人项目——拼图游戏">
<meta property="og:description" content="一、需求分析 使用像素图生成各种规格的拼图至文件 支持读取黑白、彩色的图像 使用BMP位图作为输入 题目文件数据组织结构合理，占用空间应尽量小，解析应尽量简单  二、题目文件设计对于文件的生成，我们需要从一张像素图来生成一个数组，即每行、每列的颜色点分布情况。显然根据规则，生成这个数组的方法是明确简单的。通过横向、纵向扫描数组的每一列、每一行，即可生成这个数组。最终生成的数组包含两部分，第一部分表">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://bit-wxz.gitee.io/hexo/2021/01/25/%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1%E2%80%94%E2%80%94%E6%8B%BC%E5%9B%BE%E6%96%87%E4%BB%B6%E7%94%9F%E6%88%90/1.bmp">
<meta property="og:image" content="http://bit-wxz.gitee.io/hexo/2021/01/25/%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1%E2%80%94%E2%80%94%E6%8B%BC%E5%9B%BE%E6%96%87%E4%BB%B6%E7%94%9F%E6%88%90/2.png">
<meta property="article:published_time" content="2021-01-25T15:00:00.000Z">
<meta property="article:modified_time" content="2021-02-04T09:38:04.907Z">
<meta property="article:author" content="王欣哲 1120182955">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://bit-wxz.gitee.io/hexo/2021/01/25/%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1%E2%80%94%E2%80%94%E6%8B%BC%E5%9B%BE%E6%96%87%E4%BB%B6%E7%94%9F%E6%88%90/1.bmp">
  
    <link rel="alternate" href="/hexo/atom.xml" title="软工个人项目——拼图游戏" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/hexo/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/hexo/css/style.css">

  
    
<link rel="stylesheet" href="/hexo/fancybox/jquery.fancybox.min.css">

  
<meta name="generator" content="Hexo 5.3.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/hexo/" id="logo">软工个人项目——拼图游戏</a>
      </h1>
      
        <h2 id="subtitle-wrap">
          <a href="/hexo/" id="subtitle">王欣哲 1120182955</a>
        </h2>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/hexo/">Home</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/hexo/atom.xml" title="RSS 订阅"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="搜索"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="搜索"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://BIT-WXZ.gitee.io/hexo"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-程序设计——拼图文件生成" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/hexo/2021/01/25/%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1%E2%80%94%E2%80%94%E6%8B%BC%E5%9B%BE%E6%96%87%E4%BB%B6%E7%94%9F%E6%88%90/" class="article-date">
  <time class="dt-published" datetime="2021-01-25T15:00:00.000Z" itemprop="datePublished">2021-01-25</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="p-name article-title" itemprop="headline name">
      程序设计——拼图文件生成
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h2 id="一、需求分析"><a href="#一、需求分析" class="headerlink" title="一、需求分析"></a>一、需求分析</h2><ol>
<li>使用像素图生成各种规格的拼图至文件</li>
<li>支持读取黑白、彩色的图像</li>
<li>使用BMP位图作为输入</li>
<li>题目文件数据组织结构合理，占用空间应尽量小，解析应尽量简单</li>
</ol>
<h2 id="二、题目文件设计"><a href="#二、题目文件设计" class="headerlink" title="二、题目文件设计"></a>二、题目文件设计</h2><p>对于文件的生成，我们需要从一张像素图来生成一个数组，即每行、每列的颜色点分布情况。显然根据规则，生成这个数组的方法是明确简单的。通过横向、纵向扫描数组的每一列、每一行，即可生成这个数组。最终生成的数组包含两部分，第一部分表示每行的分布情况，第二部分表示每列的分布情况。假设这张图是n*m的，则第一部分有n行，第二部分有m列。</p>
<p>而考虑多种颜色的情况下，还必须为个数字所对应的块的颜色作标注，因此还需要为每个表格另增加一个维度，以表示颜色信息。</p>
<p><img src="1.bmp" alt="黑白图片"></p>
<p>通过调色板存储拼图中所有的颜色，可以减少存储的信息内容，压缩题目的大小。最终确定拼图文件的组织格式如下：</p>
<ol>
<li>文件开始第1行存储3个整数n、m、c，表示拼图的长、宽、颜色数</li>
<li>接下来 2*n 行，每行有 ⌈m/2⌉ 个数字，2行一组，代表左侧矩阵和对应的颜色</li>
<li>接下来 2*⌈n/2⌉ 行，每行有 m 个数字，2行一组，代表上侧矩阵和对应的颜色</li>
<li>接下来 c 行，每行有3个数字，为拼图的颜色索引</li>
</ol>
<h2 id="三、程序设计"><a href="#三、程序设计" class="headerlink" title="三、程序设计"></a>三、程序设计</h2><h3 id="1、图像的读取"><a href="#1、图像的读取" class="headerlink" title="1、图像的读取"></a>1、图像的读取</h3><p>由于BMP位图的结构较为简单，因此先实现了对BMP图像的读取功能。BMP图像文件是Windows下的一种位图，它是一种图片的无损存储格式。使用Windows中的wingdi.h库，并按照BMP图像文件的组织方式可以完成对BMP图像文件的基本处理。读取后的数据经过一系列的操作后，提取颜色字典，并重新生成图像的颜色索引地图，放入Picture类的mp属性中。</p>
<p>BMP文件也有多种类型，但是均具有相同的头。在read_BMP()方法中，需要预先读取BMP头数据结构，并判断不同类型的BMP文件，以提供不同的解析方法。以24位BMP图像为例，在图像后即为图片像素点阵取值数据。这里需要注意，在每个图片的尾部会有一些空余的字节以使得像素对齐，因此需要稍加注意。在读取到颜色后，先检查是否已经有此颜色记录颜色字典，若有则在mp数组中记录颜色编号；否则将此颜色记入颜色字典，并记录颜色编号。</p>
<p>时间复杂度：O((m*n)^2)</p>
<p>时间复杂度较高，但是由于m、n的大小均不大，且在图像中颜色碰撞的概率极高，因此不做优化也可达到较高的生成速度。进一步优化可以考虑按碰撞概率构建优先队列，进一步降低扫描的时间复杂度。下面的代码展示读取、生成的代码。</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">int</span> waste;</span><br><span class="line"><span class="keyword">bool</span> op;	<span class="comment">//是否碰撞</span></span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">int</span> i = height - <span class="number">1</span>; i &gt;= <span class="number">0</span>; i--) &#123;</span><br><span class="line">	<span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; width; j++) &#123;</span><br><span class="line">		<span class="comment">//读取一颗像素</span></span><br><span class="line">		fread(&amp;pix.b, <span class="number">1</span>, <span class="number">1</span>, fp);	<span class="comment">//b</span></span><br><span class="line">		fread(&amp;pix.g, <span class="number">1</span>, <span class="number">1</span>, fp);	<span class="comment">//g</span></span><br><span class="line">		fread(&amp;pix.r, <span class="number">1</span>, <span class="number">1</span>, fp);	<span class="comment">//r</span></span><br><span class="line">		<span class="comment">//存入mp</span></span><br><span class="line">		op = <span class="literal">false</span>;</span><br><span class="line">		<span class="keyword">for</span> (<span class="keyword">int</span> c = <span class="number">0</span>; c &lt; cNum; c++) &#123;	<span class="comment">//遍历颜色字典</span></span><br><span class="line">			<span class="keyword">if</span> (Color::same(pix, dic[c])) &#123;	<span class="comment">//碰撞</span></span><br><span class="line">				op = <span class="literal">true</span>;</span><br><span class="line">				mp[i][j] = c;</span><br><span class="line">				<span class="keyword">break</span>;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span> (!op) &#123;</span><br><span class="line">			mp[i][j] = cNum;</span><br><span class="line">			dic[cNum++] = pix;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	fread(&amp;waste, <span class="number">1</span>, width % <span class="number">4</span>, fp);	<span class="comment">//读尾部空余字节</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="2、题目生成"><a href="#2、题目生成" class="headerlink" title="2、题目生成"></a>2、题目生成</h3><p>对读取到的图片进行横向、纵向的扫描，即可生成题目。在Nonograms类中提供了从Picture对象生成拼图游戏的方法。这个方法的实现较为简单，按照游戏的规则，对生成的Picture对象，按行、列扫描颜色索引，即可快速的生成题目。</p>
<p>时间复杂度：O(m*n)</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">Nonograms::generate</span><span class="params">(Picture pic)</span> </span>&#123;</span><br><span class="line">	<span class="comment">/*矩阵初始化*/</span></span><br><span class="line">	width = pic.width;</span><br><span class="line">	height = pic.height;</span><br><span class="line">	cNum = pic.cNum;</span><br><span class="line">	<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; pic.cNum; i++) &#123;	<span class="comment">//拷贝颜色字典</span></span><br><span class="line">		<span class="keyword">this</span>-&gt;dic[i] = pic.dic[i];</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; N; i++) &#123;</span><br><span class="line">		<span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; M / <span class="number">2</span>; j++) &#123;</span><br><span class="line">			a[i][j] = <span class="number">0</span>;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; N / <span class="number">2</span>; i++) &#123;</span><br><span class="line">		<span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; M; j++) &#123;</span><br><span class="line">			b[i][j] = <span class="number">0</span>;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="comment">/*生成题目*/</span></span><br><span class="line">	<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; height; i++) &#123;	<span class="comment">//左侧</span></span><br><span class="line">		<span class="keyword">int</span> p = <span class="number">0</span>;		<span class="comment">//数字的个数</span></span><br><span class="line">		<span class="keyword">int</span> num = <span class="number">0</span>;	<span class="comment">//同色块数</span></span><br><span class="line">		<span class="keyword">int</span> pc = pic.mp[<span class="number">0</span>][<span class="number">0</span>];	<span class="comment">//当前颜色</span></span><br><span class="line">		<span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; width; j++) &#123;</span><br><span class="line">			<span class="keyword">if</span> (pc == pic.mp[i][j]) &#123;	<span class="comment">//同种颜色</span></span><br><span class="line">				num++;</span><br><span class="line">			&#125;</span><br><span class="line">			<span class="keyword">else</span> &#123;	<span class="comment">//新的颜色</span></span><br><span class="line">				<span class="keyword">if</span> (pc != <span class="number">0</span>) &#123; <span class="comment">//不是白色</span></span><br><span class="line">					a[i][p] = num;</span><br><span class="line">					ac[i][p++] = pc;</span><br><span class="line">				&#125;</span><br><span class="line">				num = <span class="number">1</span>;</span><br><span class="line">				pc = pic.mp[i][j];</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span> (pc != <span class="number">0</span>) &#123; <span class="comment">//不是白色</span></span><br><span class="line">			a[i][p] = num;</span><br><span class="line">			ac[i][p++] = pc;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; width; j++) &#123;	<span class="comment">//上侧</span></span><br><span class="line">		<span class="keyword">int</span> p = <span class="number">0</span>;		<span class="comment">//数字的个数</span></span><br><span class="line">		<span class="keyword">int</span> num = <span class="number">0</span>;	<span class="comment">//同色块数</span></span><br><span class="line">		<span class="keyword">int</span> pc = pic.mp[<span class="number">0</span>][<span class="number">0</span>];	<span class="comment">//当前颜色</span></span><br><span class="line">		<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; height; i++) &#123;</span><br><span class="line">			<span class="keyword">if</span> (pc == pic.mp[i][j]) &#123;	<span class="comment">//同种颜色</span></span><br><span class="line">				num++;</span><br><span class="line">			&#125;</span><br><span class="line">			<span class="keyword">else</span> &#123;	<span class="comment">//新的颜色</span></span><br><span class="line">				<span class="keyword">if</span> (pc != <span class="number">0</span>) &#123; <span class="comment">//不是白色</span></span><br><span class="line">					b[p][j] = num;</span><br><span class="line">					bc[p++][j] = pc;</span><br><span class="line">				&#125;</span><br><span class="line">				num = <span class="number">1</span>;</span><br><span class="line">				pc = pic.mp[i][j];</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span> (pc != <span class="number">0</span>) &#123; <span class="comment">//不是白色</span></span><br><span class="line">			b[p][j] = num;</span><br><span class="line">			bc[p++][j] = pc;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="3、文件的保存"><a href="#3、文件的保存" class="headerlink" title="3、文件的保存"></a>3、文件的保存</h3><p>按照已经设计好的问题数据组织方式，使用基本的文件操作，将题目保存到.txt文件中。文件的保存功能在Nonograms类中实现。下图是一个生成的游戏数据文件样例。<br><img src="2.png" alt="游戏样例-左侧矩阵"></p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*保存到 .txt 文件*/</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">Nonograms::save</span><span class="params">(<span class="built_in">std</span>::<span class="built_in">string</span> dest)</span> </span>&#123;</span><br><span class="line">	<span class="comment">/*保存到 .txt 文件*/</span></span><br><span class="line">	FILE* fp = <span class="literal">NULL</span>;</span><br><span class="line">	<span class="keyword">if</span> ((fp = fopen(dest.c_str(), <span class="string">&quot;w&quot;</span>)) == <span class="literal">NULL</span>) &#123;</span><br><span class="line">		<span class="built_in">std</span>::<span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;Can not open file: &quot;</span> &lt;&lt; dest &lt;&lt; <span class="built_in">std</span>::<span class="built_in">endl</span>;</span><br><span class="line">		<span class="keyword">return</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">else</span> &#123;</span><br><span class="line">		<span class="built_in">fprintf</span>(fp, <span class="string">&quot;%d %d\n&quot;</span>, width, height);</span><br><span class="line">		<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; height; i++) &#123;	<span class="comment">//左侧矩阵</span></span><br><span class="line">			<span class="keyword">if</span> (a[i][<span class="number">0</span>] == <span class="number">0</span>) &#123;</span><br><span class="line">				<span class="built_in">fprintf</span>(fp,<span class="string">&quot;  0&quot;</span>);</span><br><span class="line">			&#125;</span><br><span class="line">			<span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; a[i][j] != <span class="number">0</span>; j++) &#123;</span><br><span class="line">				<span class="built_in">fprintf</span>(fp, <span class="string">&quot;%3d&quot;</span>, a[i][j]);</span><br><span class="line">			&#125;</span><br><span class="line">			<span class="built_in">fprintf</span>(fp, <span class="string">&quot;\n&quot;</span>);</span><br><span class="line"></span><br><span class="line">			<span class="keyword">if</span> (a[i][<span class="number">0</span>] == <span class="number">0</span>) &#123;</span><br><span class="line">				<span class="built_in">fprintf</span>(fp, <span class="string">&quot;  0&quot;</span>);</span><br><span class="line">			&#125;</span><br><span class="line">			<span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; a[i][j] != <span class="number">0</span>; j++) &#123;</span><br><span class="line">				<span class="built_in">fprintf</span>(fp, <span class="string">&quot;%3d&quot;</span>, ac[i][j]);</span><br><span class="line">			&#125;</span><br><span class="line">			<span class="built_in">fprintf</span>(fp, <span class="string">&quot;\n&quot;</span>);</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="built_in">fprintf</span>(fp,<span class="string">&quot;\n&quot;</span>);</span><br><span class="line">		<span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; width; j++) &#123;	<span class="comment">//上侧矩阵</span></span><br><span class="line">			<span class="keyword">if</span> (b[<span class="number">0</span>][j] == <span class="number">0</span>) &#123;</span><br><span class="line">				<span class="built_in">fprintf</span>(fp, <span class="string">&quot;  0&quot;</span>);</span><br><span class="line">			&#125;</span><br><span class="line">			<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; b[i][j] != <span class="number">0</span>; i++) &#123;</span><br><span class="line">				<span class="built_in">fprintf</span>(fp, <span class="string">&quot;%3d&quot;</span>, b[i][j]);</span><br><span class="line">			&#125;</span><br><span class="line">			<span class="built_in">fprintf</span>(fp, <span class="string">&quot;\n&quot;</span>);</span><br><span class="line"></span><br><span class="line">			<span class="keyword">if</span> (b[<span class="number">0</span>][j] == <span class="number">0</span>) &#123;</span><br><span class="line">				<span class="built_in">fprintf</span>(fp, <span class="string">&quot;  0&quot;</span>);</span><br><span class="line">			&#125;</span><br><span class="line">			<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; b[i][j] != <span class="number">0</span>; i++) &#123;</span><br><span class="line">				<span class="built_in">fprintf</span>(fp, <span class="string">&quot;%3d &quot;</span>, bc[i][j]);</span><br><span class="line">			&#125;</span><br><span class="line">			<span class="built_in">fprintf</span>(fp, <span class="string">&quot;\n&quot;</span>);</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; cNum; i++) &#123;	<span class="comment">//颜色字典</span></span><br><span class="line">			<span class="built_in">fprintf</span>(fp, <span class="string">&quot;%d %d %d\n&quot;</span>, dic[i].r, dic[i].g, dic[i].b);</span><br><span class="line">		&#125;</span><br><span class="line">		fclose(fp);</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://bit-wxz.gitee.io/hexo/2021/01/25/%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1%E2%80%94%E2%80%94%E6%8B%BC%E5%9B%BE%E6%96%87%E4%BB%B6%E7%94%9F%E6%88%90/" data-id="ckkva2tf60001nsms7e3r4ufb" data-title="程序设计——拼图文件生成" class="article-share-link">分享</a>
      
      
      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/hexo/2021/02/03/%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1%E2%80%94%E2%80%94%E9%97%AE%E9%A2%98%E6%B1%82%E8%A7%A3/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">前一篇</strong>
      <div class="article-nav-title">
        
          程序设计——问题求解
        
      </div>
    </a>
  
  
    <a href="/hexo/2020/12/28/%E6%8B%BC%E5%9B%BE%E6%B8%B8%E6%88%8F%E2%80%94%E2%80%94%E7%BB%BC%E8%BF%B0/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">后一篇</strong>
      <div class="article-nav-title">拼图游戏——综述</div>
    </a>
  
</nav>

  
</article>


</section>
        
          <aside id="sidebar">
  
    

  
    

  
    
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">归档</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/hexo/archives/2021/02/">二月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/hexo/archives/2021/01/">一月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/hexo/archives/2020/12/">十二月 2020</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/hexo/2021/02/07/%E8%BF%90%E8%A1%8C%E5%B1%95%E7%A4%BA%E2%80%94%E2%80%94GUI/">运行展示——GUI</a>
          </li>
        
          <li>
            <a href="/hexo/2021/02/07/%E8%BF%90%E8%A1%8C%E5%B1%95%E7%A4%BA%E2%80%94%E2%80%94%E5%91%BD%E4%BB%A4%E5%8F%B0/">运行展示——命令台</a>
          </li>
        
          <li>
            <a href="/hexo/2021/02/03/%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1%E2%80%94%E2%80%94%E9%97%AE%E9%A2%98%E6%B1%82%E8%A7%A3/">程序设计——问题求解</a>
          </li>
        
          <li>
            <a href="/hexo/2021/01/25/%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1%E2%80%94%E2%80%94%E6%8B%BC%E5%9B%BE%E6%96%87%E4%BB%B6%E7%94%9F%E6%88%90/">程序设计——拼图文件生成</a>
          </li>
        
          <li>
            <a href="/hexo/2020/12/28/%E6%8B%BC%E5%9B%BE%E6%B8%B8%E6%88%8F%E2%80%94%E2%80%94%E7%BB%BC%E8%BF%B0/">拼图游戏——综述</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      
      &copy; 2021 王欣哲 1120182955<br>
	  
	  
	   
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="/hexo/" class="mobile-nav-link">Home</a>
  
</nav>
    


<script src="/hexo/js/jquery-3.4.1.min.js"></script>



  
<script src="/hexo/fancybox/jquery.fancybox.min.js"></script>




<script src="/hexo/js/script.js"></script>





  </div>
</body>
</html>